﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Barbar.MapReport.Common.Drawing.Commands;
using Barbar.MapReport.Common.Drawing;
using Barbar.MapReport.Common;
using System.Drawing;
using System.Collections.ObjectModel;
using Barbar.MapReport.HtmlRender;
using Barbar.MapReport.Configuration;

public partial class GraphExample : MapReportDemoPage {
  protected void Page_Load(object sender, EventArgs e) {
    AddGraphsCommand command = new AddGraphsCommand();
    command.Colors = new Collection<SerializedColor>(new SerializedColor[] { new SerializedColor(Color.Red), new SerializedColor(Color.Purple), new SerializedColor(Color.Yellow) });
    command.ColumnWidth = 5;
    command.MaxHeight = 50;
    command.ValueFormatString = "Max for {Name} is {MaximalValue}";
    command.TitleColor = new SerializedColor(Color.Blue);
    foreach(Contact contact in DataProvider.Instance.Contacts) {
      if (contact.Latitude.HasValue && contact.Longitude.HasValue) {
        decimal[] productValues = new decimal[] { contact.Product1, contact.Product2, contact.Product3 };
        command.Points.Add(new MultipleBusinessGeoPoint(contact.Latitude.Value, contact.Longitude.Value, contact.ContactName, productValues));
      }
    }

    RenderingService renderService = new RenderingService();
    renderService.Execute(command);

    RenderSettings settings = new RenderSettings(new SerializedUnit(800), new SerializedUnit(600), 51, 11, 6, MapConfigurationManager.MapSettings.GoogleKeyProvider.DefaultGoogleKey, 2057);
    settings.EnableGoogleBar = true;

    MapHtmlFragment fragment = renderService.Render(settings);
    litMapDiv.Text = fragment.MapElement;
  }
}
